package org.jaaksi.umengshare;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMusic;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;

public class MyActivity extends Activity {

    private UMSocialService mController;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        initUmeng();
    }

    public void initUmeng() {
        // 首先在您的Activity中添加如下成员变量
        mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        // 将QQ添加到SocialSDK
        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, "100424468", "智者天下");
        qqSsoHandler.addToSocialSDK();

        // 将QQ空间添加到SocialSDK
        QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, "100424468", "智者天下");
        qZoneSsoHandler.addToSocialSDK();

        // 添加微信到SocialSDK，第三个参数为签名，！！！必须有签名
        UMWXHandler umwxHandler = new UMWXHandler(this, "100424468", "f1b603bb437db166883bb7864427092b");
        umwxHandler.addToSocialSDK();

        // 设置分享内容
        mController.setShareContent("友盟分享demo内容");
//        // 设置分享图片, 参数2为图片的url地址
//        mController.setShareMedia(new UMImage(this,
//                                              "http://www.yjz9.com/uploadfile/2014/1126/20141126115435256.jpg"));
        // 设置分享图片，参数2为本地图片的资源引用
        //mController.setShareMedia(new UMImage(getActivity(), R.drawable.icon));
        // 设置分享图片，参数2为本地图片的路径(绝对路径)
        //mController.setShareMedia(new UMImage(getActivity(),
        //                                BitmapFactory.decodeFile("/mnt/sdcard/icon.png")));

//        // 设置分享音乐
//        UMusic uMusic = new UMusic("http://sns.whalecloud.com/test_music.mp3");
//        uMusic.setAuthor("GuGu");
//        uMusic.setTitle("天籁之音");
//        // 设置音乐缩略图
//        uMusic.setThumb("http://www.yjz9.com/uploadfile/2014/1126/20141126115435256.jpg");
//        mController.setShareMedia(uMusic);

        // 设置分享视频
        UMVideo umVideo = new UMVideo(
                "http://v.youku.com/v_show/id_XNjQ2ODQ3Nzg4.html?firsttime=0&from=y1.4-2");
        // 设置视频缩略图
        umVideo.setThumb("http://www.yjz9.com/uploadfile/2014/1126/20141126115435256.jpg");
        umVideo.setTitle("分享视频!");
        mController.setShareMedia(umVideo);


        // 移除人人、豆瓣
//        mController.getConfig().removePlatform(SHARE_MEDIA.RENREN, SHARE_MEDIA.DOUBAN);
        mController.getConfig().removePlatform(SHARE_MEDIA.WEIXIN,SHARE_MEDIA.SINA);

    }

    public void show(View view) {
        // 是否只有已登录用户才能打开分享选择页
        mController.openShare(this, false);
    }

}
